package mlc;

import java.text.DecimalFormat;

public class Utils {
	
	static DecimalFormat decimalFormat = new DecimalFormat("0.##");
	
	public static int raddoppia(int a){
		return a*2;
	}
	
	public static double[] applySpeed(double startingSpeed, double deltaSpeed, double absoluteSpeedLimit){
		
		double[] result = new double[2];
		double nextSpeed = startingSpeed+deltaSpeed;		
		if(nextSpeed > absoluteSpeedLimit){
			result[0] = absoluteSpeedLimit;
			result[1] = nextSpeed - absoluteSpeedLimit;
		}else if(nextSpeed < -absoluteSpeedLimit){
			result[0] = -absoluteSpeedLimit;
			result[1] = nextSpeed + absoluteSpeedLimit;
		}else{
			result[0] = nextSpeed;
			result[1] = 0;
		}
		return result;
	}

	public static String format(double value) {
		return decimalFormat.format(value);
	}
}
